'use strict';

module.exports = app => {
    class CollectService extends app.Service {
        constructor(ctx) {
            super(ctx);
        }

        //收藏请求
        async setCollect(params) {
            const result = await this.ctx.fetch(this.app.urls('setcollect'), {
                method: 'post',
                data: {
                    type:params.type,
                    domainId:params.domainId,
                },
                dataType: 'json',
            });
            let data = result.data;

            this.app.logger.info(data);

            if (data.code != 200){
                throw new Error(data.message ? data.message : 'error');
            }

            return data;
        }

        //取消收藏
        async delCollect(params) {
            const result = await this.ctx.fetch(this.app.urls('delcollect'), {
                method: 'post',
                data: {
                    collectionIds:params.collectionIds,
                },
                dataType: 'json',
            });
            let data = result.data;

            this.app.logger.info(data);
            console.log(data)
            if (data.code != 200){
                throw new Error(data.message ? data.message : 'error');
            }

            return data.data;
        }

    }

    return CollectService;
};
